﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Frame.Pages;

public partial class EditDetailConsumer : Frame.Pages.DetailEditPage
{
    public int ComID
    {
        get
        {
            int i = 0;
            if (int.TryParse(Request.QueryString["comid"], out i))
            {
                return i;
            }
            else
            {
                return -1;
            }
        }
    }
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        if (ModelAction == Frame.Pages.ActionType.New)
        {
            this.Edit_PhoneNum.Text = Request.QueryString["PhoneNum"];
        }
    }

    DAL.BI_Consumer m_model;
    protected override object Model
    {
        get
        {
            if (m_model == null)
            {
                if (ModelAction == Frame.Pages.ActionType.New)
                {
                    m_model = new DAL.BI_Consumer();
                    if (ComID >= 0)
                    {
                        m_model.RefrenceCompany_ID = ComID;
                    }
                    m_model.UserID = -1;
                    return m_model;
                }

                int id;
                if (int.TryParse(KeyID, out id))
                {
                    m_model = this.DataSession.GetTable<DAL.BI_Consumer>().FirstOrDefault(o => o.ConsumerID == id);
                    return m_model;
                }
                else
                {
                    return null;
                }

            }
            else
            {
                return m_model;
            }

        }
    }

    protected override string ActionID
    {
        get { return "0"; }
    }

    protected override string ScriptBackUrl
    {
        get { return "EditConsumer.aspx"; }
    }
    protected void CancelBtn_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/ConsumerManage/EditConsumer.aspx");
    }
}